<?php
/**
 * @Description 測試autoconfig生成的php-model
 * @Sonkwl Xiong
 * @Date 2023/03/30 16:39:03
 * @GET 
 * 
 * @POST 
 * 
 * @Response 
 *  
 */
include '../autoload.php';
use Sonkwl\UsePHP\mysqler;
use Sonkwl\UsePHP\autodcl;

mysqler::SetPDO("mysql:dbname=test;host=localhost");
mysqler::SetUser("root");
mysqler::SetPWD("root");

$db=mysqler::GetPDO();


try{
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $db->beginTransaction();
    autodcl::BandDB($db)::BandData(array("s_name"=>"sonkwl","s_sex"=>"男"))::Use("tuser")::Do("Add")::BandData(array("s_name"=>"sonkwl2","s_sex"=>"男"))::Use("tuser")::Do("Add")::BandData(array("id"=>1,"s_sex"=>"女"))::Use("tuser")::Do("Edit")::BandData(array("id"=>2))::Use("tuser")::Do("Delete");
    $db->commit();
    echo '測試新增';
    echo '{"res":"OK"}';
}catch(Exception $e){
    $db->rollBack();
    echo '{"res":"NG","message":"新增失敗:'.$e->getMessage().'"}';
}
echo '<hr>';
?>